package com.coy.web.common.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.Serializable;


/**
 * 分页请求DTO
 * <p>
 * 建议用法：由具体业务实体继承该类
 *
 * @author chenck
 * @date 2020/8/20 9:44
 */
@Data
@Accessors(chain = true)
@ApiModel("分页请求基础入参")
public class PageInput implements Serializable {

    /**
     * 页开始下标 默认1
     */
    @ApiModelProperty(value = "页开始下标 默认1", position = 1)
    @NotNull(message = "[当前页码]不能为空")
    @Min(value = 1, message = "[当前页码]不能小于1")
    private Long pageNum = 1L;

    /**
     * 每页大小 默认10
     */
    @ApiModelProperty(value = "每页大小 默认10", required = true, position = 2)
    @NotNull(message = "[分页大小]不能为空")
    private Long pageSize = 10L;

    /**
     * 是否执行count
     * 当前页下标 <= 1，则需要count，否则不需要
     */
    public boolean isSearchCount() {
        return this.pageNum <= 1;
    }
}
